#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;

void test0()
{
    list<int> vec = {1, 3, 5, 3, 3, 3, 3, 2, 6, 7, 3, 3, 4};
    //不能删除连续重复元素
    for(auto it = vec.begin(); it != vec.end(); ++it)
    {
        if(3 == *it)
        {
            it = vec.erase(it);//第一种解法
            /* vec.erase(it++);//第二种解法 */
        }
    }

    cout << endl << "删除所有的3之后的结果:"<< endl;
    for(auto it = vec.begin(); it != vec.end(); ++it)
    {
        cout << *it << "  ";
    }
    cout << endl;
}

void test()
{
    list<int> vec = {1, 3, 5, 3, 3, 3, 3, 2, 6, 7, 3, 3, 4};
    for(auto it = vec.begin(); it != vec.end();)
    {
        if(3 == *it)
        {
            it = vec.erase(it);//ok
            /* vec.erase(it++);//ok */
        }
        else
        {
            ++it;
        }
    }

    cout << endl << "删除所有的3之后的结果:"<< endl;
    for(auto it = vec.begin(); it != vec.end(); ++it)
    {
        cout << *it << "  ";
    }
    cout << endl;
}
int main(int argc, char *argv[])
{
    test();
    return 0;
}

